package com.bw.rjx.service.impl;

import com.bw.rjx.bean.*;
import com.bw.rjx.mapper.GetDataServiceMapper;
import com.bw.rjx.service.GetDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Service
public class GetDataServiceImpl implements GetDataService {
    @Autowired
    private GetDataServiceMapper getDataServiceMapper;

    @Override
    public List<ActivityReduceStats> getActivityStats(Integer date) {
        return getDataServiceMapper.selectActivityStats(date);
    }

    @Override
    public List<CommodityIndicators> getCommodityIndicators(String shopId, String skuId, String dt1, String dt2) {
        return getDataServiceMapper.getCommodityIndicators(shopId, skuId, dt1, dt2);
    }

    @Override
    public List<DiYiZgiBao> getDwdDiYiZhou(String shopId, String skuId, String dt1, String dt2) {
        return getDataServiceMapper.getDwdDiYiZhou(shopId, skuId, dt1, dt2);
    }

    @Override
    public List<DiYiZgiBao> getDwdDiYiZhouJZR(String shopId, String skuId, String dt1, String dt2, String dt3) {
        return getDataServiceMapper.getDwdDiYiZhouJZR(shopId, skuId, dt1, dt2, dt3);
    }

    @Override
    public List<SkuSummary> getDwdDiYiZhouGroupBySkuId(String shopId, String skuId, String dt1, String dt2) {
        List<SkuSummary> dwdDiYiZhouGroupBySkuId = getDataServiceMapper.getDwdDiYiZhouGroupBySkuId(shopId, skuId, dt1, dt2);
        dwdDiYiZhouGroupBySkuId.sort(Comparator.comparing(SkuSummary::getSumFangRenCount).reversed());
        for (int i = 0; i < dwdDiYiZhouGroupBySkuId.size(); i++) {
            dwdDiYiZhouGroupBySkuId.get(i).setSumFangRenCountRank(i + 1); // 排名从1开始
        }

        dwdDiYiZhouGroupBySkuId.sort(Comparator.comparing(SkuSummary::getSumJiaNumCount).reversed());
        for (int i = 0; i < dwdDiYiZhouGroupBySkuId.size(); i++) {
            dwdDiYiZhouGroupBySkuId.get(i).setSumJiaNumCountRank(i + 1); // 排名从1开始
        }

        dwdDiYiZhouGroupBySkuId.sort(Comparator.comparing(SkuSummary::getSumPayAmount).reversed());
        for (int i = 0; i < dwdDiYiZhouGroupBySkuId.size(); i++) {
            dwdDiYiZhouGroupBySkuId.get(i).setSumPayAmountRank(i + 1); // 排名从1开始
        }
        return dwdDiYiZhouGroupBySkuId;
    }

    @Override
    public List<UserAction> getDwdDiYiZhouEr() {
        return getDataServiceMapper.getDwdDiYiZhouEr();
    }

}

